package com.HuiShou.controller.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.HuiShou.common.annotation.Log;
import com.HuiShou.common.core.controller.BaseController;
import com.HuiShou.common.core.domain.AjaxResult;
import com.HuiShou.common.enums.BusinessType;
import com.HuiShou.domain.UserPointsAccount;
import com.HuiShou.service.IUserPointsAccountService;
import com.HuiShou.common.utils.poi.ExcelUtil;
import com.HuiShou.common.core.page.TableDataInfo;

/**
 * 积分账户Controller
 * 
 * @author lyz
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/integral/account")
public class PointsAccountController extends BaseController
{
    @Autowired
    private IUserPointsAccountService userPointsAccountService;

    /**
     * 查询积分账户列表
     */
    @PreAuthorize("@ss.hasPermi('integral:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserPointsAccount userPointsAccount)
    {
        startPage();
        List<UserPointsAccount> list = userPointsAccountService.selectUserPointsAccountList(userPointsAccount);
        return getDataTable(list);
    }

    /**
     * 导出积分账户列表
     */
    @PreAuthorize("@ss.hasPermi('integral:account:export')")
    @Log(title = "积分账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserPointsAccount userPointsAccount)
    {
        List<UserPointsAccount> list = userPointsAccountService.selectUserPointsAccountList(userPointsAccount);
        ExcelUtil<UserPointsAccount> util = new ExcelUtil<UserPointsAccount>(UserPointsAccount.class);
        util.exportExcel(response, list, "积分账户数据");
    }

    /**
     * 获取积分账户详细信息
     */
    @PreAuthorize("@ss.hasPermi('integral:account:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(userPointsAccountService.selectUserPointsAccountByUserId(userId));
    }

    /**
     * 新增积分账户
     */
    @PreAuthorize("@ss.hasPermi('integral:account:add')")
    @Log(title = "积分账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserPointsAccount userPointsAccount)
    {
        return toAjax(userPointsAccountService.insertUserPointsAccount(userPointsAccount));
    }

    /**
     * 修改积分账户
     */
    @PreAuthorize("@ss.hasPermi('integral:account:edit')")
    @Log(title = "积分账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserPointsAccount userPointsAccount)
    {
        return toAjax(userPointsAccountService.updateUserPointsAccount(userPointsAccount));
    }

    /**
     * 删除积分账户
     */
    @PreAuthorize("@ss.hasPermi('integral:account:remove')")
    @Log(title = "积分账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(userPointsAccountService.deleteUserPointsAccountByUserIds(userIds));
    }
}
